
var progressArea="progressArea";
var progressMessageHolder="progressMessageHolder";

	A4J.AJAX.onError = function(req, status, message)
	{		
		if(status==500)
		{
			window.alert("Your session has expired !\nError: "+message);
			onAppTimeOut();
			alert("Please LogIn again...");
			document.location.href='LogIn.jsf';
		}
//		else
//			window.alert("Server Error...\nMessage: "+message);
		
	}
	
	A4J.AJAX.onExpired = function(loc, expiredMsg){
		if(window.confirm("Custom onExpired handler "+expiredMsg+" for a location: "+loc)){
		return loc;
		} else {
		return false;
		}
		}
	
	function setMessage(src,msg)
	{
		document.getElementById(src).innerHTML=msg;
	}

	function setVisible(src,flag)
	{
		if(flag)
			document.getElementById(src).style.visibility="visible";
		else
			document.getElementById(src).style.visibility="hidden";
	}

	function showProgress(msg)
	{
		document.getElementById(progressMessageHolder).innerHTML=msg;
		document.getElementById(progressArea).style.visibility="visible";
	}
	
	function hideProgress()
	{
		document.getElementById(progressArea).style.visibility="hidden";
	}
	
	/*
	 * Shows alert, converts each , with \n
	 */
	function showAlert(data)
	{
		var d = data.toString();
		alert( d.replace(/;/g,"\n") );
	}
	
	/*
	 * Validate the characters entered as soon as they are entered
	 * Arguments 
	 * Control inputObject : The input component object to work on
	 * Boolean flag : show alert or not
	 */	
	function validateInteger(inputObject,flag,message)
	{		
		var re = /[^0-9]/;
		if (re.exec(inputObject.value))
		{			
			if(flag)
				alert(message);
			inputObject.value = "0";
		}
	}
	
	function validateDouble(inputObject,flag,message)
	{		
		if ( isNaN(inputObject.value))
		{
			if(flag)
				alert(message);
			inputObject.value = "0";
		}
	}
	
	function validateTimeRegular(inputObject,flag,message)
	{	
		var re = /^((0[1-9])|(1[0-2])):[0-5][0-9] [aApP][mM]/;
		if (!re.exec(inputObject.value))
		{			
			if(flag)
				alert(message);
			//inputObject.value = "09:00 AM";
		}
	}
	function validateTime(inputObject,flag,message)
	{	
		var re = /^(([01][0-9])|(2[0-3])):[0-5][0-9]$/;
		if (!re.exec(inputObject.value))
		{			
			if(flag)
				alert(message);
			inputObject.value = "09:00";
		}
	}
	
	// validate length of inputObject, if flag is set, popup alert
	function validateLength(inputObject,size,flag,message)
	{
		var str ="";		
		try
		{
			if(inputObject.value.length>size)
			{
				if(flag)
					alert(message);
				str =  inputObject.value.toString();
				inputObject.value = str.substring(0, size);
			}
		}
		catch(e)
		{
			
		}
		return true;		
	}
	// 'This Process is irreversible !!!\nAre you sure to submit ?'
	function showConfirmation(message)
	{
		if(!confirm(message))
			return false;
		return true;
	}
	
	function showBusy()
	{
		Richfaces.showModalPanel('mpBusy'); 
	}
	
	function showWarning(msg)
	{
		var ele = document.getElementById('mpWarningMessage');
		ele.innerHTML = "<span>"+ msg +"</span>";
		Richfaces.showModalPanel('mpWarning'); 
	}

	function hideWarning()
	{
		Richfaces.hideModalPanel('mpWarning');
	}

	function showWarningAutoClose(msg,closeAfter)
	{
		showWarning(msg);
		setTimeout("hideWarning()",closeAfter );
	}
	
	
	function hideBusy()
	{
		Richfaces.hideModalPanel('mpBusy');
	}
	
	function isTableEmpty(formId,tableId)
	{
		var table = document.getElementById(formId+':'+tableId);	 
		var rowCount = table.rows.length;
		return rowCount <= 0;
	}
	
	function showElement(eleId, flag)
	{
		if(flag)
		{
			document.getElementById(eleId).style.display='';
		} 
		else
		{
			document.getElementById(eleId).style.display='none'; 
		}
	}
	function toggleDisplay(eleId)
	{
		var displayStyle = document.getElementById(eleId).style.display;
		if( "none" == displayStyle )
		{
			document.getElementById(eleId).style.display='';
		} 
		else
		{
			document.getElementById(eleId).style.display='none'; 
		}
	}
	
	function showLarge(ev,tar,url) {
		var ee = document.getElementById('imageEnlarged');
		ee.style.left = (ev.pageX + 50)+"px";
		ee.style.top = (ev.pageY - 120 )+"px";
        ee.src=url; 
		ee.style.visibility="visible";				
	}
	
	function hideLarge() {
		var ee = document.getElementById('imageEnlarged');
        ee.src="";
		ee.style.visibility="hidden";
	}
	
	function launchChildWindow(url) {						  			  
		wopts  = 'width=300,height=300,resizable=1,alwaysRaised=1,scrollbars=1';			  
		var neww = window.open(url,'Popup',wopts);	
				
		if (window.focus) {neww.focus();}
	}
		
	function launchChildWindow(url) {						  			  
		wopts  = 'width=300,height=300,resizable=1,alwaysRaised=1,scrollbars=1';			  
		var neww = window.open(url,'Popup',wopts);	
				
		if (window.focus) {neww.focus();}
	}

